<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <#include "/pubHeadStyleTree.html">
</head>
<body>
<div class="layui-tab layui-tab-card" style="margin: 0 6px" lay-filter="test1">
    <ul class="layui-tab-title">
        <li class="layui-this" lay-id="parameter">投票规则设置</li>
        <li lay-id="result">特权功能设置</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form" id="votingRules">
                <table class="layui-table" style="margin: 0">
                    <tbody id="tbodyMockParams">
                        <tr>
                            <td style="text-align: right;">
                                决策方式: *
                            </td>
                            <td>
                                <input type="hidden" name="signId" value="${bpmNodeSign.signId}">
                                <input type="hidden" id="nodeId" name="nodeId" value="${bpmNodeSign.nodeId}">
                                <input type="hidden" id="actDefId" name="procDefId" value="${bpmNodeSign.procDefId}">
                                <input type="radio" name="decideType" value="1" title="通过" <#if bpmNodeSign.decideType?index_of('1') != -1>checked</#if>>
                                <input type="radio" name="decideType" value="2" title="拒绝" <#if bpmNodeSign.decideType?index_of('2') != -1>checked</#if>>
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: right;">后续处理模式:</td>
                            <td>
                                <input type="radio" name="flowMode" value="1" title="直接处理 " <#if bpmNodeSign.flowMode?index_of('1') != -1>checked</#if>>
                                <input type="radio" name="flowMode" value="2" title="等待所有人投票" <#if bpmNodeSign.flowMode?index_of('2') != -1>checked</#if>>
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: right;">投票类型: </td>
                            <td>
                                <input type="radio" name="voteType" value="2" title="绝对票数" <#if bpmNodeSign.voteType?index_of('2') != -1>checked</#if>>
                                <input type="radio" name="voteType" value="1" title="百分比" <#if bpmNodeSign.voteType?index_of('1') != -1>checked</#if>>
                            </td>
                        </tr>
                        <tr>
                            <td style="text-align: right;">票数: </td>
                            <td>
                                <div class="layui-form-item" style="margin-bottom: 0;">
                                    <div class="layui-input-inline">
                                        <input type="text" name="voteAmount" class="layui-input"  lay-verify="number" value="${bpmNodeSign.voteAmount?c}">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">提示： 输入整数票数。</div>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
        <div class="layui-tab-item layui-form">
            <form class="layui-form"  id="functionalPrivilege">
                <table class="layui-table">
                    <colgroup>
                        <col width="150">
                        <col width="200">
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>特权类型</th>
                            <th>用户类型</th>
                            <th>用户来自</th>
                        </tr>
                    </thead>
                    <tbody>
                    <#list modeList as nodes>
                        <tr>
                            <td style="text-align: right;">${nodes}</td>
                            <td>
                                <select name="userType" lay-filter="aihao" class="select">
                                    <option value="1" <#if bpmNodePrivilegeArray[nodes_index].userType == 1>selected = "selected"</#if>>用户</option>
                                    <option value="3" <#if bpmNodePrivilegeArray[nodes_index].userType == 3>selected = "selected"</#if>>组织</option>
                                    <option value="4" <#if bpmNodePrivilegeArray[nodes_index].userType == 4>selected = "selected"</#if>>组织负责人</option>
                                    <option value="7" <#if bpmNodePrivilegeArray[nodes_index].userType == 7>selected = "selected"</#if>>用户属性</option>
                                    <option value="12" <#if bpmNodePrivilegeArray[nodes_index].userType == 12>selected = "selected"</#if>>脚本</option>
                                </select>
                            </td>
                            <td>
                                <textarea style="display: none;" name="cmpIds" class="hiddenJson">${bpmNodePrivilegeArray[nodes_index].cmpIds}</textarea>
                                <textarea name="cmpNames" style="width:70%;border-color: #D2D2D2!important;line-height: 20px;vertical-align: bottom;"class="textarea" readonly="readonly">${bpmNodePrivilegeArray[nodes_index].cmpNames}</textarea>
                                <a class="windowButton layui-btn layui-btn-sm" style="" ><span>选择...</span></a>
                                <a class="empty layui-btn layui-btn-sm" style="" ><span>清除</span></a>
                            </td>
                        </tr>
                    </#list>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>
<textarea id="tbodyPreview"  style="display: none;" >
			<tr>
				<td>发起人:</td>
				<td>
					<input type="text" name="startUserId" readonly="readonly" value="" previewId=""/>
					<a class="button"><span class="chosen">选择</span></a>
				</td>
			</tr>
</textarea>

<!--<div class="layui-btn-container" style="text-align: center;position: absolute;bottom: 15px;left: 0px;right: 0px;">-->
    <!--<button class="layui-btn" lay-submit id="preview">预览</button>-->
    <!--<button class="layui-btn layui-btn-danger" id="close">关闭</button>-->
<!--</div>-->

<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','layer', 'form', 'element','setter','jquery','table'], function() {
        var layer = layui.layer
            , form = layui.form
            , $ = layui.jquery
            ,table = layui.table
            ,setter = layui.setter
            , element = layui.element;
        var modelId  = "${modelId}";
        //"用户来自"选择元素的不同弹窗设置
        $(document).off('click','.windowButton').on('click', '.windowButton', function () {
            // $('.windowButton').click(function () {
            var theData = $(this).siblings(".textarea");
            var hiddenData = $(this).siblings(".hiddenJson");
            //获取当前行的选中值
            var val= $(this).parent().parent().find('.select').val();
            //弹窗名称
            var windowUrl = '';
            //弹窗路径
            var windowTitle='';
            //弹窗参数（JSON格式）
            var cmpIds  = $(this).siblings(".hiddenJson").html();
            //JSON参数中特殊符号转义处理
            cmpIds = cmpIds.replace("\"", "%22").replace("{", "%7b").replace("}", "%7d");
            //根据获取的id值，判断选择弹窗的路径
            var userSelectorWin;
            var orgSelectorWin;
            var itemName='';
            var itemId='';
            var body;
            switch (val) {
                case '1':
                    layer.open({
                        type:2
                        ,title:'人员选择器'
                        ,area:['980px','630px']
                        ,btn:["保存","取消","撤销"]
                        ,resize:false
                        ,content: serverPath.systemPath + setter.sysLinkPath+'dialog/view/sysUserDialog'
                        ,success: function(layero, index){
                            body = layer.getChildFrame('body',index);
                            userSelectorWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            //向用户选择器页面传递初始值[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                            if (theData.text()) {
                                userSelectorWin.layui.userList = [];
                                var hiddenDataArr = hiddenData.text().split(",");
                                var theDataArr = theData.text().split(",");
                                $.each(hiddenDataArr,function (k,v) {
                                    var userListObj={};
                                    userListObj.name = theDataArr[k];
                                    userListObj.userId = v;
                                    userSelectorWin.layui.userList.push(userListObj);
                                })
                            }
                        }
                        ,yes:function(index,layero){
                            var theUserList = body.find("input[name=userList]").val();
                            if (theUserList){
                                //用户选择器返回的选择人员数组[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                                $.each(JSON.parse(theUserList),function (index, item) {
                                    itemName += item.name + ",";
                                    itemId += item.userId + ",";
                                });
                                if (itemName.length > 0) {
                                    itemName = itemName.substr(0,itemName.length - 1);
                                    itemId = itemId.substr(0,itemId.length - 1);
                                }
                                theData.html(itemName);
                                hiddenData.html(itemId);
                            }else{
                                theData.html('');
                                hiddenData.html('');
                            }
                            layer.close(index);
                        }
                        ,btn3:function(index, layero){
                            userSelectorWin.cancelData(index);
                            return false //开启该代码可禁止点击该按钮关闭
                        }
                    });
                    break;
                case '3':
                    layer.open({
                        type: 2
                        , title: '组织选择器'
                        , area: ['980px', '630px']
                        ,btn:["保存","取消","撤销"]
                        , resize: false
                        , content: serverPath.systemPath + setter.sysLinkPath+ 'dialog/view/sysOrgDialog'
                        ,success: function(layero, index){
                            body = layer.getChildFrame('body',index);
                            orgSelectorWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            //向用户选择器页面传递初始值[{name:"name1",userId:"userId1"},{name:"name2",userId:"userId2"}...]
                            if (theData.text()) {
                                orgSelectorWin.layui.orgList = [];
                                var hiddenDataArr = hiddenData.text().split(",");
                                var theDataArr = theData.text().split(",");
                                $.each(hiddenDataArr,function (k,v) {
                                    var orgListObj={};
                                    orgListObj.name = theDataArr[k];
                                    orgListObj.orgId = v;
                                    orgSelectorWin.layui.orgList.push(orgListObj);
                                })
                            }
                        }
                        ,yes: function(index, layero){
                            var orgList = body.find("input[name=orgList]").val();
                            if (orgList){
                                $.each(JSON.parse(orgList),function (index, item) {
                                    itemName += item.name + ",";
                                    itemId += item.orgId + ",";
                                });
                                if (itemName.length > 0) {
                                    itemName = itemName.substr(0,itemName.length - 1);
                                    itemId = itemId.substr(0,itemId.length - 1);
                                };
                            }
                            theData.html(itemName);
                            hiddenData.html(itemId);
                            layer.close(index);
                        }
                        ,btn3:function(index, layero){
                            orgSelectorWin.cancelData(index);
                            return false //开启该代码可禁止点击该按钮关闭
                        }
                    });
                    break;
                case '12':
                    scriptClick(theData,hiddenData);
                    // windowTitle = '脚本选择';
                    // windowUrl = '/workflow/bpmNodeUser/view/userWindowScript?modelId=${modelId}&&nodeId=${nodeId}&windowName=script';
                    break;
            };
            //弹窗统一格式
            if(windowTitle.length>0&&windowUrl.length>0) {
                $('#windowUrls').load(windowUrl);
                layer.open({
                    title: windowTitle,
                    type: 1,
                    shade: 0.3,
                    area: ['90%', '90%'],
                    // area: ['500px', '380px'],
                    content: $('#windowUrls'),
                    btn:['保存','关闭'],
                    success:function(layero,index){
                    },
                    yes:function (index,layero) {//index 为当前页面索引，layero 为当前页面的DOM，所以可以利用下面的方式获取
                        if ($(".windowName").text()=="personScript") {
                            var hiddenJson = 'return (';
                            var showTxt    = '(';
                            //获取select参数值
                            $('.layui-table .paraCtType').each(function(){
                                var _val = $(this).val();
                                if(_val!=0) {
                                    hiddenJson  += (_val + ',');
                                    showTxt     += (_val + ';');
                                }
                            });
                            //获取input参数值
                            $('.layui-table #paraCtType').each(function(){
                                var _this = $(this);
                                if(_this.attr("type")!='hidden'){
                                    hiddenJson += (_this.val()+',');
                                    showTxt    += (_this.val()+';');
                                }
                            });
                            //对前弹窗文本域赋值
                            if(showTxt.length>0) {
                                hiddenJson = hiddenJson.substring(0, hiddenJson.lastIndexOf(',')) + ')';
                                showTxt = showTxt.substring(0, showTxt.lastIndexOf(';')) + ')';
                            }
                            hiddenData.html(hiddenJson);
                            theData.html(showTxt);
                            // 关闭弹窗
                            layer.close(index);
                        }else if ($(".windowName").text()=="sameNodeDepartment"||$(".windowName").text()=="sameNode"){
                            var hiddenJson = '{nodeId:\"'+$("td input:checked").val()+'\"}';
                            var data = $("td input:checked").attr("nodeName");

                            //对前弹窗文本域赋值
                            hiddenData.html(hiddenJson);
                            theData.html(data);
                            //关闭弹窗
                            layer.close(index);
                            return false;
                        }else if($(".windowName").text()=="startOrPrevWithOrg"||$(".windowName").text()=="startOrPrev"){
                            //获取选中的按钮
                            var type    = $("input[name=type]:checked").val();
                            var userType= $("input[name=userType]:checked").val();
                            var isOrg   = $("input[name=isOrg]").val();
                            var varTypeName    = $("input[name=type]:checked").attr("memo");
                            var varUserTypeName= $("input[name=userType]:checked").attr("memo");

                            var hiddenJson ='{type:\"'+type+'\",userType:\"'+userType+'\"}';
                            var showTxt;
                            if(!isOrg){
                                //执行人
                                showTxt=varUserTypeName +"的"+varTypeName;
                            }else{
                                //执行人的部门
                                showTxt='与'+varUserTypeName +'具有'+varTypeName;;
                            }
                            //对前弹窗的文本域赋值
                            hiddenData.html(hiddenJson);
                            theData.html(showTxt);
                            //关闭弹窗
                            layer.close(layer.index);
                            return false;
                        }else if ($(".windowName").text()=="orgTypeUserLeader"){
                            //获取选中的按钮
                            var demId = $("input[name=demensionId]:checked").val();
                            var level=$(' select[name=level]').val();
                            var orgSource=$('input:radio[name=orgSource]:checked').val();
                            var isUpQuery = $('input:radio[name=isUpQuery]:checked').val();

                            var orgSourceText = $("input:radio[name=orgSource]:checked").next('span').html();
                            var levelText = $('select[name=level]').find("option:selected").text();
                            var isUpQueryText = $("input:radio[name=isUpQuery]:checked").next('span').html();

                            var hiddenJson ="{\"demId\":\""+demId+"\",\"orgSource\":\""+orgSource+"\",\"level\":\""+level+"\",\"isUpQuery\":"+isUpQuery+"}";
                            var showTxt="类型:"+orgSourceText+";部门类型:"+levelText+";查找策略:"+isUpQueryText;
                            //对前弹窗的文本域赋值
                            hiddenData.html(hiddenJson);
                            theData.html(showTxt);
                            // 关闭弹窗
                            layer.close(index);
                            return false;
                        }else if($(".windowName").text()=="script"){
                            //获取本弹窗添加的值
                            InitMirror.editor.save();
                            var data = $('#typeScript').val();
                            //对前弹窗文本域赋值
                            theData.html(data);
                            hiddenData.html(data);
                            //关闭弹窗
                            layer.close(layer.index);
                            return false;
                        }

                        // var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        // parent.layer.close(index1); //再执行关闭
                    }
                });
            }
        });
        //清空
        $(document).off('click','.empty').on('click', '.empty', function () {
            $(this).siblings(".textarea").html('');
            $(this).siblings(".hiddenJson").html('');
        });
        //监听select
        form.on('select', function(data){
            $(data.elem).parent().parent().find("textarea").html('');
        });
        //脚本弹出层
        function scriptClick(theData,hiddenData) {
            parent.layer.open({
                title:'脚本',
                type: 2,
                shade: 0.3,
                btn:["保存","关闭"],
                skin: 'btn-class',
                area: ['80%', '90%'],
                content: serverPath.workflowPath + setter.workflowLinkPath +'bpmNodeUser/view/script?modelId='+modelId,
                // content: $('#windowUrls')
                yes:function (index,layero) {
                    //获取iframe的body元素
                    var body = parent.layer.getChildFrame('body',index);
                    //得到iframe页的窗口对象
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    //执行iframe页的showMsg方法
                    var theDiv = iframeWin.frames[0].document.children[0].getElementsByClassName("editbox")[0].innerText;
                    theData.html(theDiv);
                    parent.layer.close(index);
                }
                // });
            });
        };

    })
</script>
</body>
</html>